Skip to content

Docs (DialogMd data input): addresses confusion with injecting data - #3907

Merged
jelbourn merged 6 commits into
angular:masterfrom
M-a-c:dialogRef-data-in
Apr 17, 2017
Merged

jelbourn merged 6 commits into
angular:masterfrom
M-a-c:dialogRef-data-in

Conversation

@M-a-c

@M-a-c M-a-c commented Apr 4, 2017 •

Copy link
Copy Markdown
Contributor

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Apr 4, 2017
Comment thread src/lib/dialog/dialog.md Outdated
})

export class DialogName {
constructor@Inject(MD_DIALOG_DATA) public data: any) { }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing (

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL how on earth? Must have hit the backspace key switching just before commit, that's super weird..

Comment thread src/lib/dialog/dialog.md Outdated
value is forwarded as the result of the `afterClosed` promise.

### Sharing Data with the Dialog component.
Depending on what you are doing you might want to share data with your dialog component. Angular has documentation that explains in general how to share data between any components using [`services`](https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should talk about services here, because they're a general Angular pattern. We should mention the data option instead.

@M-a-c M-a-c Apr 6, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree. Should that ever be addressed in Angular Material documentation? Since a lot of the components are interactive, services seem pretty fundamental to the 'passing data problem' I started with Angular 3 months ago, and I was introduced to services by a few other developers asking why I was doing everything so backwards. I'm glad they brought it up, because in the long run it made my code a lot easier to understand.

  • Is there a spot that we could expose users to services? (lots of us are beginners)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's Material's responsibility to expose users to services.

Comment thread src/lib/dialog/dialog.md Outdated
})

export class DialogName {
constructor( @Inject(MD_DIALOG_DATA) public data: any ) { }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do spaces between the braces. It should be constructor(@Inject(MD_DIALOG_DATA) public data: any) { }.

Comment thread src/lib/dialog/dialog.md Outdated

Passing outside data to your component is as simple as.
```ts
import {MdDialog} from '@angular/material';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this example it's pretty obvious where MdDialog comes from so you can remove this line and the private dialog: MdDialog.

Comment thread src/lib/dialog/dialog.md Outdated
private dialog: MdDialog;

let dialogRef = dialog.open(DialogName, {
data:'your data',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a space between the : and the string.

Comment thread src/lib/dialog/dialog.md
Here is an example component you can pass data to.
```ts
import {Component, Inject} from '@angular/core';
import {MD_DIALOG_DATA} from '@angular/material';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can leave the imports here since the injection is slightly more convoluted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment thread src/lib/dialog/dialog.md Outdated
import {MD_DIALOG_DATA} from '@angular/material';

@Component({
selector: 'dialog-selector',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try renaming this to something like your-dialog and the class to YourDialog.

Comment thread src/lib/dialog/dialog.md Outdated
value is forwarded as the result of the `afterClosed` promise.

### Sharing Data with the Dialog component.
Depending on what you are doing you might want to share data with your dialog component. The dialog component has a data option that you can include in order to pass data from the open to the dialog.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add backticks(`) around "data" in "The dialog component has a data option".

Comment thread src/lib/dialog/dialog.md Outdated
value is forwarded as the result of the `afterClosed` promise.

### Sharing Data with the Dialog component.
Depending on what you are doing you might want to share data with your dialog component. The dialog component has a `data` option allowing you to pass data to the component.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for all the requests, but can you reword this to "If you want to share data with your dialog, you can use the data option to pass information to the dialog component.". Also if you remove the "Passing outside data to your component is as simple as." sentence the PR will be good to go.

Comment thread src/lib/dialog/dialog.md Outdated
});
```

Here is an example component you can pass data to.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to "To access the data in your dialog component, you have to use the MD_DIALOG_DATA injection token:"?

Comment thread src/lib/dialog/dialog.md Outdated
constructor(@Inject(MD_DIALOG_DATA) public data: any) { }
}
```

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you reduce the amount of extra blank lines here? This is mainly for consistency.

@M-a-c

M-a-c commented Apr 13, 2017 •

Copy link
Copy Markdown
Contributor Author

Yeah your wording is a lot more crisp. I need to work on this my wording before I make more contributions.
Short sweet and to the point. Thanks for being patient crisbeto.

@crisbeto crisbeto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@crisbeto crisbeto added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Apr 14, 2017
@henriquefm

Copy link
Copy Markdown

Just a small detail: the name of the dialog class in dialog.open(DialogName, ... (line 36) is different from the actual class on line 51, export class YourDialog.

@jelbourn
jelbourn merged commit 9f2c7ac into angular:master Apr 17, 2017
@M-a-c
M-a-c deleted the dialogRef-data-in branch April 17, 2017 19:20
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Documentation is unclear about how to get data into a Dialog.

6 participants